{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.6 Reduced Port Ball Valve"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Water is discharged at 15 degrees Celsius from a tank with 7 m of head to atmosphere through:\n",
    "\n",
    "* 60 meters of 80 mm schedule 40 pipe\n",
    "* Six 80 mm standard 90 degree threaded elbows\n",
    "* One 80 mm flanged ball valve, with a 60 mm diameter seat, 16 degree conical inlet and 30 degree conival outlet.\n",
    "* The entrance is sharp-edged and flush with the tank"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Velocity = 2.77004132376 meter / second\n",
      "Flow rate = 792.547439913 liter / minute\n"
     ]
    }
   ],
   "source": [
    "from thermo.units import Chemical\n",
    "from fluids.units import *\n",
    "from math import pi\n",
    "water = Chemical('water', T=15*u.degC)\n",
    "rho = water.rho\n",
    "mu = water.mu\n",
    "\n",
    "H = 7*u.m\n",
    "L = 60*u.m\n",
    "fd = 0.017 # assumed in their example\n",
    "NPS, D_pipe, Do_pipe, t = nearest_pipe(Do=80*u.mm)\n",
    "\n",
    "K = K_from_f(fd=fd, L=L, D=D_pipe)\n",
    "K += entrance_sharp()\n",
    "K += exit_normal()\n",
    "K += 6*bend_rounded(D_pipe, angle=90*u.degrees, fd=fd, bend_diameters=0.65)\n",
    "ball_valve_angle = 0.5*(15+30)*u.degrees # use the average angle\n",
    "K += K_ball_valve_Crane(D1=D_pipe, D2=60*u.mm, angle=ball_valve_angle, fd=fd)\n",
    "\n",
    "v = (2*u.gravity*H/K)**0.5\n",
    "print('Velocity = %s' %v.to_base_units())\n",
    "Q = v*pi/4*D_pipe**2\n",
    "print('Flow rate = %s' %Q.to(u.L/u.min))\n",
    "Re = Reynolds(D=D_pipe, rho=rho, mu=mu, V=v)\n",
    "fd = friction_factor(Re=Re, eD=0.0018*u.inch/D_pipe)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The radius of curvature of the elbows was not specified; 0.65 bend diameters matches their results most closely. They modified the ball valve equation to support both an inlet and an outlet angle; the average value is used here.\n",
    "\n",
    "Their calculated values are 2.74 m/s and flow rate of 781 L/min.\n",
    "\n",
    "The calculation can be performed more accurately by iterating; a naive approach is shown below. A very different flow rate is obtained when the roughness of the pipe is considered in the friction factor calculation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Flow rate = 792.547439913 liter / minute\n",
      "Flow rate = 473.249278655 liter / minute\n",
      "Flow rate = 472.693638206 liter / minute\n",
      "Flow rate = 472.692023884 liter / minute\n",
      "Flow rate = 472.692019188 liter / minute\n",
      "Flow rate = 472.692019174 liter / minute\n",
      "Flow rate = 472.692019174 liter / minute\n"
     ]
    }
   ],
   "source": [
    "fd = 0.017\n",
    "for i in range(7):\n",
    "    K = K_from_f(fd=fd, L=L, D=D_pipe)\n",
    "    K += entrance_sharp()\n",
    "    K += exit_normal()\n",
    "    K += 6*bend_rounded(D_pipe, angle=90*u.degrees, fd=fd, bend_diameters=0.65)\n",
    "    ball_valve_angle = 0.5*(15+30)*u.degrees # use the average angle\n",
    "    K += K_ball_valve_Crane(D1=D_pipe, D2=60*u.mm, angle=ball_valve_angle, fd=fd)\n",
    "\n",
    "    v = (2*u.gravity*H/K)**0.5\n",
    "    Q = v*pi/4*D_pipe**2\n",
    "    print('Flow rate = %s' %Q.to(u.L/u.min))\n",
    "    Re = Reynolds(D=D_pipe, rho=rho, mu=mu, V=v)\n",
    "    fd = friction_factor(Re=Re, eD=0.0018*u.inch/D_pipe)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
